package br.com.lvc.bicho;

import br.com.lvc.bicho.standartgame.TextSpeech;
import android.content.Context;
import android.view.View;
import android.view.animation.Animation;
import android.view.animation.Animation.AnimationListener;
import android.widget.ImageView;

public class AnimalButton extends ImageView {

	private Context context;
	private int sound;
	private TextSpeech resTextToSpeech;
	
	public AnimalButton(Context context,final CallbackTextToSpeechAnimalButton callbackAnimalButton, final int drawable, final TextSpeech resTextToSpeech, int sound) {
		super(context);
		this.context = context; 
		this.resTextToSpeech = resTextToSpeech;
		this.sound = sound;
		
		setBackgroundDrawable(getResources().getDrawable(drawable));
		
		setOnClickListener(new View.OnClickListener() {
			
			public void onClick(View v) {
				Animation animationSize = AnimationController.createAnimationIncreaseSize(v.getContext()); 
				animationSize.setAnimationListener(new MyAnimationListener());
				v.startAnimation(animationSize);
				callbackAnimalButton.pressed((AnimalButton)v);
			
			}
		});
	}
	
	public AnimalButton(Context context,final CallbackTextToSpeechAnimalButton callbackAnimalButton, final int drawable, int sound) {
		super(context);
		this.context = context; 
		
		this.sound = sound;
		
		setBackgroundDrawable(getResources().getDrawable(drawable));
		
		setOnClickListener(new View.OnClickListener() {
			
			public void onClick(View v) {
				callbackAnimalButton.pressed((AnimalButton)v);
			}
		});
	}
	
	public void startAlphaAnimation() {
    	Animation animation = AnimationController.createAnimationAlpha(context);
    	startAnimation(animation);
    }
	
	
	public TextSpeech getResTextToSpeech() {
		return resTextToSpeech;
	}
	

	public int getSound() {
		return sound;
	}
	
	
	public void setSound(int sound) {
		this.sound = sound;
	}
	

	private class MyAnimationListener implements AnimationListener {

		public void onAnimationEnd(Animation animation) {
			startAlphaAnimation();
			
		}

		public void onAnimationRepeat(Animation animation) {
			
			
		}

		public void onAnimationStart(Animation animation) {
			
			
		}
		
	}


	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result + sound;
		return result;
	}

	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (getClass() != obj.getClass())
			return false;
		AnimalButton other = (AnimalButton) obj;
		if (sound != other.sound)
			return false;
		return true;
	}
	
	

}